ASP.NET Core有兩個Swagger生成工具可以用
NSwag安裝指令dotnet add package NSwag.AspNetCore
官方給的指令有包含依賴檔的名稱dotnet add NSwagSample.csproj package NSwag.AspNetCore
可以自己修改想要的依賴檔,或是就不加
然後Program.cs加入這幾行
builder.Services.AddControllers();
// 這行可以去設定Swagger文件資料
builder.Services.AddOpenApiDocument(options =>
{
    options.PostProcess = document =>
    {
        document.Info = new NSwag.OpenApiInfo
        {
            Version = "v1",
            Title = "Leni API",
            Description = "An ASP.NET Core Web API for article platform"
        };
    };
});
// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
    // Add OpenAPI 3.0 document serving middleware
    // Available at: http://localhost:<port>/swagger/v1/swagger.json
    app.UseOpenApi();
    // Add web UIs to interact with the document
    // Available at: http://localhost:<port>/swagger
    app.UseSwaggerUi(); // UseSwaggerUI Protected by if (env.IsDevelopment())
}
dotnet run
今天有點忙碌,差點就停更了,最近都只能稍微前進一點點